package com.guigu.controller;


import com.guigu.pojo.UserAddress;
import com.guigu.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户地址表 前端控制器
 * </p>
 *
 * @author Mr.Zhang
 * @since 2025-03-12
 */
@CrossOrigin
@RestController
@RequestMapping("/user-address")
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    //根据consumerId查询地址
    @GetMapping("/getAddressById")
    @ResponseBody
    public Object getAddressByConsumerId(Integer consumerId) {
        List<UserAddress> addressByConsumerId = userAddressService.getAddressByConsumerId(consumerId);
        return addressByConsumerId;
    }

    @PostMapping("/AddAddress")
    @ResponseBody
    public Boolean AddAddress(@RequestBody UserAddress userAddress) {
        boolean save = userAddressService.save(userAddress);
        return save;
    }

    @PostMapping("/updateAddress")
    @ResponseBody
    public Boolean updateAddress(@RequestBody List<UserAddress> userAddress) {
        boolean update = userAddressService.updateBatchById(userAddress);
        return update;
    }

}

